
//Eli Elder
//scoreFor
//makefile needs this
//unittest1: unittest1.c dominion.o rngs.o
//	gss -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)


#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h> 
#include <assert.h>
#include <math.h>
#include "rngs.h"

//set PRINTOUT to 0 to remove printfs out
//set assertive to 0 to remove assertive thigns that stop my tests
#define PRINTOUT 1
#define ASSERTIVE 0

int main() {
    int i;
    int numPlayers = 1;
    int numDeck = MAX_DECK;
    int numDiscard = MAX_DECK;
    int numHand = MAX_HAND;
    int initialized;
    struct gameState theGameState;
    int kingCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, salvager};
    //setup arrays for hands
    int curseHand[MAX_HAND];
    int estateHand[MAX_HAND];
    int duchyHand[MAX_HAND];
    int provinceHand[MAX_HAND];
    int great_hallHand[MAX_HAND];
    int gardensHand[MAX_HAND];
    //setup arrays for deck.discard(the max)
    int curseDeckDis[MAX_DECK];
    int estateDeckDis[MAX_DECK];
    int duchyDeckDis[MAX_DECK];
    int provinceDeckDis[MAX_DECK];
    int great_hallDeckDis[MAX_DECK];
    int gardensDeckDis[MAX_DECK];
    //just to test for gardens without adding points 
    int coppersHand[MAX_HAND];
    int coppersDeck[MAX_DECK];
    //setup arrays of hands full of the card needed
    for(i = 0; i < MAX_HAND; i++){
	curseHand[i] = curse;
	estateHand[i] = estate;
	duchyHand[i] = duchy;
	provinceHand[i] = province;
	great_hallHand[i] = great_hall;
	gardensHand[i] = gardens;
	coppersHand[i] = copper;
    }

    //setup the arrays of decks full of the cards needed
    for(i = 0; i < MAX_DECK; i++){
	curseDeckDis[i] = curse;
	estateDeckDis[i] = estate;
	duchyDeckDis[i] = duchy;
	provinceDeckDis[i] = province;
	great_hallDeckDis[i] = great_hall;
	gardensDeckDis[i] = gardens;
	coppersDeck[i] = copper;
    }
    
    
    
    //curse
    //clear the hand and setup the game
    memset(&theGameState, 23, sizeof(struct gameState)); 
    initialized = initializeGame(numPlayers, kingCards, 1, &theGameState);
    //force the hand to be full of  curse cards
    theGameState.handCount[numPlayers] = numHand;
    memcpy(theGameState.hand[numPlayers], curseHand, sizeof(int) * MAX_HAND);
    
    //setup the discard/deck so we dont seg fault
    theGameState.deckCount[numPlayers] = 0;
    theGameState.discardCount[numPlayers] = 0;
    
    
    
#if (PRINTOUT == 1)
    printf("score for curse = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numHand * -1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numHand * -1);
#endif
    
    //esatate
    //force the hand to be full of  estate cards
    memcpy(theGameState.hand[numPlayers], estateHand, sizeof(int) * numHand);
    
    
#if (PRINTOUT == 1)
    printf("score for estate = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numHand * 1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numHand * 1);
#endif    
    //duchy
    //force the hand to be full of  duchy cards
    memcpy(theGameState.hand[numPlayers], duchyHand, sizeof(int) * numHand);
    
    
#if (PRINTOUT == 1)
    printf("score for duchy = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numHand * 3);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numHand * -3);
#endif	
    //province
    //force the hand to be full of  province cards
    memcpy(theGameState.hand[numPlayers], provinceHand, sizeof(int) * numHand);
    
    
#if (PRINTOUT == 1)
    printf("score for province = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numHand * 6);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numHand * 6);
#endif
    //great_hall
    //force the hand to be full of  great_hall cards
    memcpy(theGameState.hand[numPlayers], great_hallHand, sizeof(int) * numHand);
    
    
#if (PRINTOUT == 1)
    printf("scorefor greathall = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numHand * 1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numHand * 1);
#endif	
    //gardens
    //force the hand to be full of  gardens cards
    memcpy(theGameState.hand[numPlayers], gardensHand, sizeof(int) * numHand);
    theGameState.deckCount[numPlayers] = MAX_DECK;
    memcpy(theGameState.deck[numPlayers], coppersDeck, sizeof(int) * MAX_DECK);
    
#if (PRINTOUT == 1)
    printf("scorefor gardens = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numHand * (theGameState.deckCount[numPlayers] + theGameState.handCount[numPlayers] + theGameState.discardCount[numPlayers]) / 10);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numHand * (theGameState.deckCount[numPlayers] + theGameState.handCount[numPlayers] + theGameState.discardCount[numPlayers]) / 10);
#endif
    
    
    
    //test all decks
    
    //curse
    //clear the deck and setup the game
    memset(&theGameState, 23, sizeof(struct gameState)); 
    initialized = initializeGame(numPlayers, kingCards, 1, &theGameState);
    //force the deck to be full of  curse cards
    theGameState.deckCount[numPlayers] = numDeck;
    memcpy(theGameState.deck[numPlayers], curseDeckDis, sizeof(int) * numDeck);
    
    //setup the discard/hand so we dont seg fault
    theGameState.handCount[numPlayers] = 0;
    theGameState.discardCount[numPlayers] = 0;

#if (PRINTOUT == 1)
    printf("scorefor curse = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDeck * -1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDeck * -1);
#endif
    //esatate
    //force the deck to be full of  estate cards
    memcpy(theGameState.deck[numPlayers], estateDeckDis, sizeof(int) * numDeck);
    
    
#if (PRINTOUT == 1)
    printf("scorefor estate = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDeck * 1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDeck * 1);
#endif	
    //duchy
    //force the deck to be full of  duchy cards
    memcpy(theGameState.deck[numPlayers], duchyDeckDis, sizeof(int) * numDeck);
    
    
#if (PRINTOUT == 1)
    printf("scorefor duchy = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDeck * 3);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDeck * -3);
#endif	
    //province
    //force the deck to be full of  province cards
    memcpy(theGameState.deck[numPlayers], provinceDeckDis, sizeof(int) * numDeck);
    
    
#if (PRINTOUT == 1)
    printf("scorefor province = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDeck * 6);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDeck * 6);
#endif		
    //great_hall
    //force the deck to be full of  great_hall cards
    memcpy(theGameState.deck[numPlayers], great_hallDeckDis, sizeof(int) * numDeck);
    
    
#if (PRINTOUT == 1)
    printf("scorefor greathall = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDeck * 1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDeck * 1);
#endif	
    //gardens
    //force the deck to be full of  gardens cards
    memcpy(theGameState.deck[numPlayers], gardensDeckDis, sizeof(int) * numDeck);
    theGameState.handCount[numPlayers] = MAX_HAND;
    memcpy(theGameState.hand[numPlayers], coppersHand, sizeof(int) * MAX_HAND);
    
#if (PRINTOUT == 1)
    printf("scorefor gardens = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDeck * (theGameState.deckCount[numPlayers] + theGameState.handCount[numPlayers] + theGameState.discardCount[numPlayers]) / 10);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDeck * (theGameState.deckCount[numPlayers] + theGameState.handCount[numPlayers] + theGameState.discardCount[numPlayers]) / 10);
#endif
    
    
    //test all discards
    
    //curse
    //clear the discard and setup the game
    memset(&theGameState, 23, sizeof(struct gameState)); 
    initialized = initializeGame(numPlayers, kingCards, 1, &theGameState);
    //force the discard to be full of  curse cards
    theGameState.discardCount[numPlayers] = numDiscard;
    memcpy(theGameState.discard[numPlayers], curseDeckDis, sizeof(int) * numDiscard);
    
	//setup the hand/deck so we dont seg fault
    theGameState.deckCount[numPlayers] = 0;
    theGameState.handCount[numPlayers] = 0;
    
#if (PRINTOUT == 1)
    printf("scorefor curse = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDiscard * -1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDiscard * -1);
#endif
	
    //esatate
    //force the discard to be full of  estate cards
    memcpy(theGameState.discard[numPlayers], estateDeckDis, sizeof(int) * numDiscard);
    
    
#if (PRINTOUT == 1)
    printf("scorefor estate = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDiscard * 1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDiscard * 1);
#endif
    
    //duchy
    //force the discard to be full of  duchy cards
    memcpy(theGameState.discard[numPlayers], duchyDeckDis, sizeof(int) * numDiscard);
    
	
#if (PRINTOUT == 1)
    printf("scorefor duchy = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDiscard * 3);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDiscard * -3);
#endif
    
    //province
    //force the discard to be full of  province cards
    memcpy(theGameState.discard[numPlayers], provinceDeckDis, sizeof(int) * numDiscard);
    
    
#if (PRINTOUT == 1)
    printf("scorefor province = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDiscard * 6);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDiscard * 6);
#endif
    //great_hall
    //force the discard to be full of  great_hall cards
    memcpy(theGameState.discard[numPlayers], great_hallDeckDis, sizeof(int) * numDiscard);
    
    
#if (PRINTOUT == 1)
    printf("scorefor greathall = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDiscard * 1);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDiscard * 1);
#endif
    //gardens
    //force the discard to be full of  gardens cards
    memcpy(theGameState.discard[numPlayers], gardensDeckDis, sizeof(int) * numDiscard);
    theGameState.handCount[numPlayers] = MAX_HAND;
    memcpy(theGameState.hand[numPlayers], coppersHand, sizeof(int) * MAX_HAND);
    
#if (PRINTOUT == 1)
    printf("scorefor gardens = %d, expected %d\n", scoreFor(numPlayers, &theGameState), numDiscard * (theGameState.deckCount[numPlayers] + theGameState.handCount[numPlayers] + theGameState.discardCount[numPlayers]) / 10);
#endif
#if (ASSERTIVE == 1)
    assert(scoreFor(numPlayers, &theGameState) == numDiscard * (theGameState.deckCount[numPlayers] + theGameState.handCount[numPlayers] + theGameState.discardCount[numPlayers]) / 10);
#endif
    
    return 0;
}
